package top.riske.animalhazardassessment.account.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import top.riske.animalhazardassessment.account.service.AccountService;
import top.riske.animalhazardassessment.common.DTO.AccountDto;
import top.riske.animalhazardassessment.common.http.exception.BusinessException;

@Tag(name = "AccountController",description = "用户信息管理")
@Slf4j
@RestController
public class AccountController {

    @Resource
    private AccountService accountService;

    @Operation(summary = "更新用户信息，上面的所有信息都能改，没有权限验证")
    @PostMapping("/account/updateUserInfo")
    public boolean updateUserInfo(@RequestBody AccountDto accountDto) {
        if(accountDto.getId() == null){
            throw new BusinessException("用户id不能为空");
        }
        return accountService.updateById(accountDto.toEntity());
    }

    @Operation(summary = "获取用户信息")
    @GetMapping("/account/getUserInfo")
    public AccountDto getUserInfo(Long id) {
        if(id == null){
            throw new BusinessException("用户id不能为空");
        }
        return accountService.getById(id).toDto();
    }

    @Operation(summary = "删除用户")
    @GetMapping("/account/deleteAccount")
    public boolean deleteAccount(Long id){
        if(id == null){
            throw new BusinessException("用户id不能为空");
        }
        return accountService.removeById(id);
    }

}
